﻿#light

module Dwarf_MapReduce_Generator

open System
open System.IO

let Dwarf_MapReduce_Generator (fs : FileStream, args : String[]) = 
// constants
    let count_of_symbols_in_kilobyte = 1024

    // subsidiary objects
    let writer = new StreamWriter(fs)
    let rand = new Random()

    // current data values
    let count_of_kilobytes = (int) args.[args.Length - 1]
    let expected_file_size = (int64) count_of_kilobytes * (int64) count_of_symbols_in_kilobyte
    let mutable dictionary_path = ""

    for i = 0 to args.Length - 2 do                                     
        if (args.[i] = "-dictionarypath") then          // search for user-defined dictionary path in args
            dictionary_path <- args.[i + 1]

    if (dictionary_path = "") then
        raise (new Exception("The value of '-dictionarypath' parameter is not specified"))
        
    DictionaryProcessor.generateFile(dictionary_path, writer, expected_file_size, rand)
 
    writer.Close()
    
    true